/*################################################*/
/*    A SA-MP RolePlay Project Written by Stella  */
/*          Started on 31/03/2011 21:33           */
/*#################################################*/


/*
 * RECORDATORIOS - IDEAS SIN HACER
 * 1- /descripcion (poner en tu cabeza lo que ocurre en tu cuerpo)
 * 2- Crear cuenta bancaria antes de usar
 * 3- Telefono
 * 4- Sistema de meadas
 * 5- Comedor de presidiarios
 * 6- Deteccion de choque de autos
 * */
stock Lol()
{
llamar();

}
 
#define SetPlayerHoldingObject(%1,%2,%3,%4,%5,%6,%7,%8,%9) SetPlayerAttachedObject(%1,MAX_PLAYER_ATTACHED_OBJECTS-1,%2,%3,%4,%5,%6,%7,%8,%9)
#define StopPlayerHoldingObject(%1) RemovePlayerAttachedObject(%1,MAX_PLAYER_ATTACHED_OBJECTS-1)
#define IsPlayerHoldingObject(%1) IsPlayerAttachedObjectSlotUsed(%1,MAX_PLAYER_ATTACHED_OBJECTS-1)
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
	

#pragma tabsize 0
#pragma unused ret_memcpy
#include <a_samp>
#include <dini>
#include <dudb>
 
/*#################################################*/
/*        Server info consts                       */
/*#################################################*/ 

#define        VERSION "0.1 ALPHA"
#define           MODE "Stella RP " VERSION
#define        MAPNAME "Stella RP"
#define MAX_OUTPUT_MSG 700
#define    MAX_CMD_LEN 30
#define     MAX_ALARMS 200

/*#################################################*/
/*    Skin and clothe system Handlers              */
/*#################################################*/

#define D_SHOPCLOTHES_ENTRY_HANDLER 25
#define        D_SHOPCLOTHES_BUY_OK 26
#define     D_SHOPCLOTHES_BUY_ERROR 27
#define    D_SHOPCLOTHES_BUY_ERROR2 28
#define      D_SHOPCLOTHES_BUY_INFO 29

#define                         MEN 0
#define                        GIRL 1 
new   pos_Girl[MAX_PLAYERS];
new    pos_Boy[MAX_PLAYERS];
new IsPlayerOnShop[MAX_PLAYERS];
new     Sex_clothe[MAX_PLAYERS];
new      FirstSkin[MAX_PLAYERS];
new Boy_Skins[] =
{
	0,1,2,7,14,15,17,19,20,21,22,23,24,25,
	29,32,33,34,35,36,37,43,44,46,48,49,51,
	52,58,59,60,61,66,67,68,72,73,78,79,
};

new Girl_Skins[] =
{
	12,13,151,169,263,216,214,215,226,76,89,
	88,218,40,41,
};



/*#################################################*/
/*           Countrys Consts                       */
/*#################################################*/

#define     C_SPAIN 0
#define   C_ECUADOR 1 
#define C_VENEZUELA 2 
#define C_ARGENTINA 3 
#define    C_MEXICO 4
#define     C_OTHER 5

/*#################################################*/
/*        Factions Consts                          */
/*#################################################*/

#define          FA_POLICE 1
#define   FA_RUSSIAN_MAFIA 2
#define           FA_MEDIC 3
#define      FA_MOTORBIKES 4
#define     FA_ITALY_MAFIA 5
#define        FA_MECHANIC 6
#define            FA_ARMY 7
#define FA_BLACK_GANGSTERS 8
#define       FA_PRESIDENT 9
#define         FA_LV_NEWS 10

/*#################################################*/
/*        Jobs Consts                              */
/*#################################################*/

#define  JOB_BUS_DRIVER 0
#define JOB_TAXI_DRIVER 1
#define       JOB_PIZZA 2
#define      JOB_CORREO 3
#define    JOB_GUARDIAN 4 
#define        JOB_PUTA 5



/*#################################################*/
/*        PlayerInfo Vars                          */
/*#################################################*/

enum PlayerData 
{
pId, pPassword, 
pMoney, pAge, pDriveLicense, pWeaponLicense,
pBankMoney, pMarried, pAdminLevel, pFaction, 
pFactionLevel, pJailed, pJailedTime, pBan, pJob, pCountry,
pHavePhone, pPhoneNumber, pHaveBankAccount, pBankAccount,
pSkin, pDriveTeoric,
}; 

new Text:         DrawName[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][PlayerData];
new           IsLogged[MAX_PLAYERS] = 0;

/*#################################################*/
/*        Test dialogs Handlers                    */
/*#################################################*/
#define ERR_ANSWER 500
#define  OK_ANSWER 499
#define INIT_STEP1  0
#define INIT_STEP2  1
#define INIT_STEP3  2 
#define DI_ANSWER0  3
#define DI_ANSWER1  4
#define DI_ANSWER2  5
#define DI_ANSWER3  6
#define DI_ANSWER4  7
#define DI_ANSWER5  8
#define DI_ANSWER6  9
#define DI_ANSWER7  10
#define DI_ANSWER8  11
#define DI_ANSWER9  12
#define DI_ANSWER10 13
#define DI_ANSWER11 14
#define DI_ANSWER12 15
#define DI_ANSWER13 16

/*#################################################*/
/*        Login / Register Handlers                */
/*#################################################*/

#define DI_REGISTER 17
#define    DI_LOGIN 18
#define      DI_AGE 19
#define DI_RUNSTYLE 20
#define  DI_COUNTRY 21
#define DI_PASSWORD 22
forward SpawnRegisteringPlayer(playerid);
new                     Age[MAX_PLAYERS];
new                 Country[MAX_PLAYERS];
new           IsRegistering[MAX_PLAYERS];

/*#################################################*/
/*             Agenda Const                        */
/*#################################################*/

#define    A_SHOWMENU 23
#define A_LIST_PHONES 24

/*#################################################*/
/*        Objects Handlers                         */
/*#################################################*/

new LVPD_GATE;


/*#################################################*/
/*        Test dialogs aux vars                    */
/*#################################################*/

new     correctAnswers[MAX_PLAYERS];

/*#################################################*/
/*        LV - Pickups handlers                    */
/*#################################################*/

new     P_ENTRY_LVPD;
new     P_EXIT_LVPD;
new     P_ENTRY2_LVPD;
new     P_EXIT2_LVPD;
new     P_ACADEMY_LVPD;
new     P_ENTRY_CASINO;
new     P_ENTRY_BURGERSHOT;
new     P_ENTRY_BURGERSHOT2;
new     P_ENTRY_HOSPITAL;
new     P_ENTRY_SHOP_CLOTHES;
new     P_EXIT_SHOP_CLOTHES;
new     P_CHANGE_CLOTHES;
new     P_UP_LVPD;
new     P_UP2_LVPD;
new     P_DOWN_LVPD;
new     P_SHOP_LV;
new     P_PATIO_ENTRY;
new     P_PATIO_EXIT;

/*#################################################*/
/*                   Stuff                         */
/*#################################################*/
new   AlarmCount[MAX_ALARMS];
new                 AlarmNow; 
new AlarmHandler[MAX_PLAYERS];
forward AlarmSound(vehicleid, id, playerid);
new engine, lights, alarm, doors, bonnet, boot, objective;



main()
{
	SetGameModeText(MODE);
	printf("Stella RolePlay project written by Stella (aka n3ptun0)");
	printf("Version: " VERSION);
	return 1;
}

public OnGameModeInit()
{
	
	ShowPlayerMarkers(0);
	DisableInteriorEnterExits();
	
	LVPD_GATE = CreateObject(971, 200.12127685547, 159.59106445313, 1004.5933837891, 0, 0, 268);
	/* Draw name properties */
	for(new h =0; h < MAX_PLAYERS; h++)
	{ 
	DrawName[h] = TextDrawCreate(50.000000, 425.000000, "Kevin_Stella");
	TextDrawBackgroundColor(DrawName[h], 255);
	TextDrawFont(DrawName[h], 1);
	TextDrawLetterSize(DrawName[h], 0.400000, 1.399999);
	TextDrawColor(DrawName[h], -1);
	TextDrawSetOutline(DrawName[h], 0);
	TextDrawSetProportional(DrawName[h], 1);
	TextDrawSetShadow(DrawName[h], 1);
    }
    /* Carcel Objects */
    CreateObject(3279, 2327.1965332031, -1546.2086181641, 23.42179107666, 0, 0, 270);
    CreateObject(3279, 2281.6987304688, -1543.9224853516, 25.555654525757, 0, 0, 0);
    CreateObject(3279, 2327.6499023438, -1516.3768310547, 24.132953643799, 0, 0, 270);
    CreateObject(8417, 2313.6616210938, -1550.3381347656, 34.654117584229, 0, 270, 87.499328613281);
    CreateObject(8417, 2296.71484375, -1549.1583251953, 34.654117584229, 0, 270, 87.4951171875);
    CreateObject(8417, 2276.8840332031, -1529.5565185547, 34.654117584229, 0, 270, 0.24325561523438);
    CreateObject(3279, 2281.41796875, -1515.4599609375, 25.555654525757, 0, 0, 0);
    CreateObject(8417, 2313.751953125, -1510.8876953125, 34.654117584229, 0, 268.74993896484, 270.74230957031);
    CreateObject(8417, 2295.994140625, -1511.1827392578, 34.654117584229, 0, 268.74993896484, 270.74224853516);
    CreateObject(8417, 2331.8837890625, -1528.5083007813, 34.654117584229, 0, 270, 0.24169921875);
    CreateObject(8417, 2331.8212890625, -1532.5078125, 34.654117584229, 0, 270, 179.98986816406);
    CreateObject(987, 2303.6552734375, -1549.7464599609, 24.400022506714, 0, 0, 89.5);
    CreateObject(987, 2303.8227539063, -1522.8662109375, 24.400022506714, 0, 0, 89.49462890625);
    CreateObject(3819, 2294.7873535156, -1546.5970458984, 26.872758865356, 0, 0, 269);
    CreateObject(3819, 2279.5598144531, -1525.8217773438, 26.872758865356, 0, 0, 179.99993896484);
    CreateObject(14781, 2287.2131347656, -1536.9545898438, 26.965349197388, 0, 0, 0);
    CreateObject(851, 2304.7434082031, -1548.5828857422, 24.816808700562, 0, 358, 90);
    CreateObject(1439, 2297.3776855469, -1511.8331298828, 25.875, 0, 0, 0);
    CreateObject(1439, 2310.0153808594, -1512.0260009766, 24.758728027344, 0, 0, 0);
    CreateObject(2675, 2300.0656738281, -1543.7180175781, 25.939260482788, 0, 0, 0);
    CreateObject(2674, 2311.5454101563, -1513.3575439453, 24.365489959717, 0, 0, 0);
    CreateObject(2674, 2306.3918457031, -1511.7464599609, 24.990480422974, 0, 24, 284);
    CreateObject(2114, 2313.4970703125, -1514.5733642578, 24.490060806274, 0, 0, 0);
    CreateObject(2114, 2299.5432128906, -1514.1098632813, 26.021310806274, 0, 0, 0);
    CreateObject(2915, 2284.6032714844, -1532.8442382813, 25.996162414551, 0, 0, 324);
    CreateObject(2913, 2291.4482421875, -1540.7418212891, 25.999998092651, 0, 270, 349.99990844727);
    CreateObject(1616, 2309.7502441406, -1549.689453125, 35.089874267578, 0, 0, 0);
    CreateObject(1616, 2331.7810058594, -1539.2534179688, 33.097583770752, 0, 0, 0);
    CreateObject(2627, 2285.8735351563, -1515.0806884766, 25.875, 0, 0, 0);
    CreateObject(2628, 2299.4431152344, -1518.9945068359, 25.875, 0, 0, 269.5);
    CreateObject(2629, 2294.109375, -1514.8010253906, 25.875, 0, 0, 0);
    CreateObject(2630, 2297.431640625, -1515.8542480469, 25.875, 0, 0, 0);
    CreateObject(2630, 2289.2565917969, -1514.9234619141, 25.875, 0, 0, 0);
    CreateObject(2913, 2294.5751953125, -1514.2679443359, 26.699987411499, 0, 269.24981689453, 359);
    CreateObject(18100, 2292.6320800781, -1527.73046875, 25.924999237061, 0, 0, 0);


	/* Create pickups */
    P_ENTRY_LVPD = CreatePickup(1318, 23, 2290.14086900, 2429.87548800, 10.91477900, 0);
    P_EXIT_LVPD = CreatePickup(1318, 23, 238.5314, 140.3750, 1003.0234, 0);
    P_ENTRY2_LVPD = CreatePickup(1318, 23, 2340.52490200, 2458.55786100, 14.48821800, 0);
    P_EXIT2_LVPD = CreatePickup(1318, 23, 288.1984, 168.3417, 1007.1719, 0);
    P_ACADEMY_LVPD = CreatePickup(1318, 23, 1044.63635300, 1014.78253200, 11.49444900, 0);
    P_ENTRY_CASINO = CreatePickup(1318, 23, 2020.41455100, 1007.84613000, 10.73977000, 0);
    P_ENTRY_BURGERSHOT = CreatePickup(1318, 23, 2478.91577100, 2034.58239700, 11.15695500, 0);
    P_ENTRY_BURGERSHOT2 = CreatePickup(1318, 23, 1885.88452100, 2080.75170900, 10.98195700, 0);
    P_ENTRY_HOSPITAL = CreatePickup(1318, 23, 1606.20556600, 1816.77832000, 10.61477200, 0);
    P_UP_LVPD = CreatePickup(1318, 23, 2296.8562, 2468.5842, 10.8203, 0);
    P_UP2_LVPD = CreatePickup(1318, 23, 2296.8291, 2451.5237, 10.8203, 0);
    P_DOWN_LVPD = CreatePickup(1318, 23, 274.1699, 185.9534, 1007.1719, 0);
    P_SHOP_LV = CreatePickup(1318, 23, 1952.1315,1342.9600,15.3746, 0);
    P_PATIO_ENTRY = CreatePickup(1318, 23, 188.4828,158.1772,1003.0234, 0);
    P_PATIO_EXIT = CreatePickup(1318, 23, 2277.6724,-1536.4681,26.8750, 0);
    P_ENTRY_SHOP_CLOTHES = CreatePickup(1318, 23, 2102.4980,2264.2207,11.0234, 0);
    P_EXIT_SHOP_CLOTHES = CreatePickup(1318, 23, 161.3944,-96.7426,1001.8047, 0);
    P_CHANGE_CLOTHES = CreatePickup(1318, 23, 181.4218,-91.5893,1002.0234, 0);
    /* ################################################################### */
    /*               Russian Mafia Static Vehicles                         */
    /* ################################################################### */
    AddStaticVehicleEx(545,1471.4047,2800.5105,10.5524,126.9881,47,1, 0); // 
    AddStaticVehicleEx(545,1464.3850,2790.7351,10.5528,158.0932,47,1, 0); // 
    AddStaticVehicleEx(545,1462.3198,2776.4434,10.5532,180.2925,47,1, 0); // 
    AddStaticVehicleEx(545,1463.7157,2758.7258,10.5528,191.8458,47,1, 0); // 
    AddStaticVehicleEx(545,1478.0503,2742.7927,10.5531,250.6022,47,1, 0); // 
    AddStaticVehicleEx(545,1529.7963,2818.3833,10.6314,88.8275,47,1, 0); // 
    AddStaticVehicleEx(545,1529.2958,2795.9165,10.6314,91.9610,47,1, 0); // 
    AddStaticVehicleEx(545,1529.7228,2827.3220,10.6314,90.7993,47,1, 0); // 

    /* ################################################################### */
    /*                    LV-PD Static Vehicles                            */
    /* ################################################################### */
    AddStaticVehicleEx(599,2251.6072,2443.4653,10.5474,179.2289,116,1, 0); // LVPD
	AddStaticVehicleEx(523,2259.9519,2443.3530,10.5567,179.2289,116,1, 0); // LVPD
	AddStaticVehicleEx(598,2290.6938,2442.9407,10.5639,179.2289,116,1, 0); // LVPD
	AddStaticVehicleEx(523,2294.8760,2442.8840,10.5401,179.2289,116,1, 0); // LVPD
	AddStaticVehicleEx(599,2251.7495,2458.3560,10.5474,0.8129,116,1, 0); // LVPD Fila 2
	AddStaticVehicleEx(598,2255.7979,2458.4136,10.5585,0.8129,116,1, 0); // LVPD Fila 2
	AddStaticVehicleEx(523,2259.8003,2458.4707,10.5547,0.8129,116,1, 0); // LVPD Fila 2

	AddStaticVehicleEx(599,2294.9351,2477.0330,10.5474,359.0565,116,1, 0); // LVPD Fila 3
	AddStaticVehicleEx(598,2290.8035,2477.1008,10.5638,359.0565,116,1, 0); // LVPD Fila 3
	AddStaticVehicleEx(523,2282.7930,2477.2327,10.5475,359.0565,116,1, 0); // LVPD Fila 3

	AddStaticVehicleEx(523,2252.2405,2477.7356,10.5448,359.0565,116,1, 0); // LVPD Fila 3
	
    /* ###################################################################*/
    /*                   Taxi Driver Static Vehicles                      */
    /* ###################################################################*/
	AddStaticVehicleEx(420,2175.1423,2351.1274,10.5231,90.9608,6,1, 0); // 
    AddStaticVehicleEx(420,2157.0293,2353.3547,10.5220,71.9750,6,1, 0); // 
    AddStaticVehicleEx(420,2141.9299,2357.2158,10.5213,83.9549,6,1, 0); // 
    AddStaticVehicleEx(420,2113.2048,2356.4019,10.5235,289.6133,6,1, 0); // 
    AddStaticVehicleEx(420,2101.1296,2351.7117,10.5230,301.0142,6,1, 0); // 
    AddStaticVehicleEx(420,2091.9001,2344.7930,10.5229,321.0401,6,1, 0); // 

	return 1;
}

/*#################################################*/
/*        OnPlayerPickUpPickup                     */
/*#################################################*/

public OnPlayerPickUpPickup(playerid, pickupid)
{
	if(pickupid == P_CHANGE_CLOTHES)
	{
		SetPlayerPos(playerid, 182.0279,-88.0571,1002.0234);
		IsPlayerOnShop[playerid] = 1;
		ShowPlayerDialog(playerid,D_SHOPCLOTHES_ENTRY_HANDLER,DIALOG_STYLE_MSGBOX,"Selecciona tu sexo","Seleccione que tipo de prenda desea", "Hombre", "Mujer");
	}
	if(pickupid == P_EXIT_SHOP_CLOTHES)
	{
		if(IsPlayerOnShop[playerid] == 1)
		{
			SetPlayerSkin(playerid, FirstSkin[playerid] );
			pos_Girl[playerid] = 0;
			pos_Boy[playerid] = 0;
			IsPlayerOnShop[playerid] = 0;
			TogglePlayerControllable(playerid, 1);
		}
		SetPlayerInterior(playerid, 0);
		SetPlayerPos(playerid, 2104.7891,2263.5496,11.0234);
	}
	
	if(pickupid == P_ENTRY_SHOP_CLOTHES)
	{
		SetPlayerInterior(playerid, 18);
		SetPlayerPos(playerid, 161.4048,-94.2416,1001.8047);
		GameTextForPlayer(playerid, "~w~~r~Tienda de ropa", 6000, 3);
	}
	if(pickupid == P_PATIO_ENTRY)
	{
		SetPlayerInterior(playerid, 0);
		SetPlayerPos(playerid,  2280.3953,-1533.6382,26.8750);
		GameTextForPlayer(playerid, "~w~~r~Patio de presidiarios", 6000, 3);
	}
	if(pickupid == P_PATIO_EXIT)
	{
		SetPlayerInterior(playerid, 3);
		SetPlayerPos(playerid, 193.0002,158.3169,1003.0234);
		GameTextForPlayer(playerid, "~w~~r~Modulo de celdas", 6000, 3);
	}
	if(pickupid == P_ENTRY_LVPD)
	{
		GameTextForPlayer(playerid, "~w~~r~Departamento de Policias de LV", 6000, 3);
		SetPlayerPos(playerid, 238.6252, 142.2370, 1003.0234);
		SetPlayerInterior(playerid, 3);
	}

	if(pickupid == P_ENTRY2_LVPD)
	{
	    GameTextForPlayer(playerid, "~w~~r~Departamento de Policias de LV", 6000, 3);
	    SetPlayerPos(playerid, 289.4879, 174.1790, 1007.1794);
		SetPlayerInterior(playerid, 3);
	}

	if(pickupid == P_EXIT_LVPD)
	{
	    SetPlayerPos(playerid, 2290.0005, 2427.3679, 10.8203);
	    SetPlayerInterior(playerid, 0);
	}

	if(pickupid == P_EXIT2_LVPD)
	{
	    SetPlayerPos(playerid, 2340.0681, 2455.8403, 14.9688);
	    SetPlayerInterior(playerid, 0);
	}

	if(pickupid == P_UP_LVPD || pickupid == P_UP2_LVPD)
	{
		GameTextForPlayer(playerid, "~w~~r~Departamento de Policias de LV", 6000, 3);
	    SetPlayerPos(playerid, 276.5718, 183.4800, 1007.1719);
	    SetPlayerInterior(playerid, 3);
	}

	if(pickupid == P_DOWN_LVPD)
	{
		GameTextForPlayer(playerid, "~w~~r~Estacionamiento de LVPD", 6000, 3);
	    SetPlayerPos(playerid, 2294.2393, 2459.1267, 10.8203);
	    SetPlayerInterior(playerid, 0);
	}
	return 1;
}

/*#################################################*/
/*        OnPlayerUpdate                           */
/*#################################################*/

public OnPlayerUpdate(playerid)
{

	return 1;
}

/*#################################################*/
/*        OnPlayerSpawn                            */
/*#################################################*/

public OnPlayerSpawn(playerid)
{
	SetPlayerMapIcon( playerid, 0, 2020.41455100, 1007.84613000, 10.73977000, 44, 0, MAPICON_LOCAL); 
	SetPlayerMapIcon( playerid, 1, 2340.3372,2452.4341,14.9742, 30, 0, MAPICON_LOCAL);
	SetPlayerMapIcon( playerid, 2, 1952.1315,1342.9600,15.3746, 17, 0, MAPICON_LOCAL);
	SetPlayerMapIcon( playerid, 12,1463.7157,2758.7258,10.5528, 23, 0, MAPICON_LOCAL );
	SetPlayerMapIcon( playerid, 12,2102.4980,2264.2207,11.0234, 45, 0, MAPICON_LOCAL );
	
	SetPlayerColor(playerid, 0xFFFF00AA);
	if(IsRegistering[playerid] == 1)
	{
		SetPlayerSkin(playerid, 26);
		IsRegistering[playerid] = 0;
		CallRegisterFinally(playerid);
		return 1;
	}
	if(IsLogged[playerid] == 0)
	{
		Kick(playerid);
		return 1;
	}
	else
	{
		SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
		SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
		SelectSpawn(playerid);
	}
	
	return 1;
}

/*#################################################*/
/*        OnPlayerConnect                          */
/*#################################################*/

public OnPlayerConnect(playerid)
{
	
	new PlayerName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName) );
	new file[MAX_PLAYER_NAME + 15]; 
    format(file, sizeof(file), "usuarios/%s.ini", PlayerName);
    if( fexist(file) ) { 
		CallLogin(playerid);
	} else{
		CallAnswers(playerid);
	}	
    
    return 1;
}

/*#################################################*/
/*        OnDialogResponse                         */
/*#################################################*/

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == D_SHOPCLOTHES_ENTRY_HANDLER)
	{
		FirstSkin[playerid] = GetPlayerSkin(playerid);
		if(response) //The player select a MEN
		{
			Sex_clothe[playerid] = MEN;
		}
		else         //The player select a GIRL
		{
			Sex_clothe[playerid] = GIRL;
		}
		ShowPlayerDialog(playerid, D_SHOPCLOTHES_BUY_INFO, DIALOG_STYLE_MSGBOX, "Informacion", "-Colocate frente al espejo y usa el [CLICK] del raton\n-Para comprar la vestimenta presiona [ESPACIO]\n-Podras mover a tu personaje en distintos angulos para ver como te sienta tu ropa", "Aceptar", "");
		
	}
	if(dialogid == INIT_STEP1)
	{
		ShowPlayerDialog(playerid,INIT_STEP2,DIALOG_STYLE_MSGBOX,"Atencion","En este servidor seguimos un estricto control del rol. Antes de proceder al registro, le haremos un cuestionario.", "Aceptar", "");
    }
    
    if(dialogid == INIT_STEP2)
	{
		ShowPlayerDialog(playerid,INIT_STEP3,DIALOG_STYLE_MSGBOX,"Atencion","El motivo de hacer una evaluacion es valorar sus conocimientos de Rol.\nSi no esta de acuerdo haga click en Cancelar","Acepto","Cancelar");
    }
    
    if(dialogid == INIT_STEP3)
	{
	   	if(!response)
 		{
			Kick(playerid);
	    }
		else
		{
			AnswersTest(DI_ANSWER0, playerid);
	    }
    }
   
   	if(dialogid == DI_ANSWER0)
   	{
   		if( listitem == 2 )
	   	{
	   		correctAnswers[playerid]++;
	   	}
	   	AnswersTest(DI_ANSWER1, playerid);
   	}
   	
   	if(dialogid == DI_ANSWER1)
   	{
   		if(listitem == 1)
	   	{
	   		correctAnswers[playerid]++;
   		}
	   	AnswersTest(DI_ANSWER2, playerid);
   	}
   	
   	if(dialogid == DI_ANSWER2)
   	{
   		if(listitem == 2)
	   	{
		   correctAnswers[playerid]++;
   		}
	   	AnswersTest(DI_ANSWER3, playerid);
   	}
   	
   	if(dialogid == DI_ANSWER3)
   	{
   		if(listitem == 0)
	   	{
	   		correctAnswers[playerid]++;
	   	}
	   	AnswersTest(DI_ANSWER4, playerid);
   	}
   	if(dialogid == DI_ANSWER4)
	{
 		if(listitem == 3)
 		{
   			correctAnswers[playerid]++;
	   	}
	   	AnswersTest(DI_ANSWER5, playerid);
   	}
   	if(dialogid == DI_ANSWER5)
   	{
		if(listitem == 2)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER6, playerid);
	}
	if(dialogid == DI_ANSWER6)
	{
		if(listitem == 2)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER7, playerid);
	}
	if(dialogid == DI_ANSWER7)
	{
		if(listitem == 0)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER8, playerid); 
	}
	if(dialogid == DI_ANSWER8)
	{
		if(listitem == 3)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER9, playerid);
	}

	if(dialogid == DI_ANSWER9)
	{
		if(listitem == 3)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER10, playerid);
	}

	if(dialogid == DI_ANSWER10)
	{
		if(listitem == 1)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER11, playerid);
	}

	if(dialogid == DI_ANSWER11)
	{
		if(listitem == 0)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER12, playerid);
	}

	if(dialogid == DI_ANSWER12)
	{
		if(listitem == 1)
		{
			correctAnswers[playerid]++;
		}
		AnswersTest(DI_ANSWER13, playerid);
	}


	if(dialogid == DI_ANSWER13)
	{
		if(listitem == 0)
		{
			correctAnswers[playerid]++;
		}
		
		if(correctAnswers[playerid] < 14)
		{
			ShowPlayerDialog(playerid, ERR_ANSWER, DIALOG_STYLE_MSGBOX, "Error", "{AA3333}Lo sentimos, no has superado el examen inicial para poder ingresar al servidor", "Aceptar", "");
			Kick(playerid);
		}
		else
		{
			ShowPlayerDialog(playerid, OK_ANSWER, DIALOG_STYLE_MSGBOX, "Prueba superada", "{33AA33}Felicidades, haz completado el examen inicial con exito", "Aceptar", "");
		}
		
	}
	if(dialogid == OK_ANSWER)
	{
		
		
	    new tmp[1024];
	    for (new i = 16; i < 61; i++)
	    {
		    new edad[3];
		    format(edad, sizeof(edad), "%d", i);
		    strcat(tmp, edad);
		    strcat(tmp, "\n");
	    }
	    ShowPlayerDialog(playerid,DI_AGE,DIALOG_STYLE_LIST,"Que edad tiene su personaje",tmp,"Aceptar", "");
	}
	if(dialogid == DI_AGE)
	{
		Age[playerid] = listitem + 16;
		ShowPlayerDialog(playerid,DI_COUNTRY,DIALOG_STYLE_LIST,"Dime de donde proviene su personaje","{AA3333}Esp{FFFF00}ana\n{FFFF00}Ec{0000BB}ua{AA3333}dor\n{FFFF00}Vene{0000BB}zu{AA3333}ela\n{0000FF}Arg{FFFFFF}en{0000FF}tina\n{33AA33}Mex{FFFFFF}i{AA3333}co\nOtro pais","Aceptar", "");	
	}
	if(dialogid == DI_COUNTRY)
	{
		Country[playerid] = listitem;
		ShowPlayerDialog(playerid,DI_PASSWORD,DIALOG_STYLE_INPUT,"Introduce una clave","Introduce la clave de tu cuenta","Aceptar","");
	}
	if(dialogid == DI_PASSWORD)
	{
		if(!strlen(inputtext))
        {
            ShowPlayerDialog(playerid,DI_PASSWORD,DIALOG_STYLE_INPUT,"Introduce una clave","Introduce la clave de tu cuenta","Aceptar","");
            
        }
        else
        {
		    CallRegister(playerid, Age[playerid], Country[playerid], inputtext);
		    IsRegistering[playerid] = 1;
		    SpawnPlayer(playerid);
		}
	}
	if(dialogid == DI_LOGIN)
	{
		new PlayerName[MAX_PLAYER_NAME];
		new file[MAX_OUTPUT_MSG + 15];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        format(file, sizeof(file), "usuarios/%s.ini", PlayerName);	
        
        new pass[256];
        
        pass = dini_Get(file, "pPassword");	
        
        if(strval(pass) == udb_hash(inputtext))
        {
		   IsLogged[playerid] = 1;
           PlayerInfo[playerid][pId] = dini_Int(file, "pId"); 
           PlayerInfo[playerid][pPassword] = dini_Int(file, "pPassword");
           PlayerInfo[playerid][pMoney] = dini_Int(file, "pMoney");
           PlayerInfo[playerid][pAge] = dini_Int(file, "pAge");
           PlayerInfo[playerid][pDriveLicense] = dini_Int(file, "pDriveLicense");
           PlayerInfo[playerid][pWeaponLicense] = dini_Int(file, "pWeaponLicense");
           PlayerInfo[playerid][pBankMoney] = dini_Int(file, "pBankMoney");
           PlayerInfo[playerid][pMarried] = dini_Int(file, "pMarried");
           PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "pAdminLevel");
           PlayerInfo[playerid][pFaction] = dini_Int(file, "pFaction");
           PlayerInfo[playerid][pFactionLevel] = dini_Int(file, "pFactionLevel");
           PlayerInfo[playerid][pJailed] = dini_Int(file, "pJailed");
           PlayerInfo[playerid][pJailedTime] = dini_Int(file, "pJailedTime");
           PlayerInfo[playerid][pBan] = dini_Int(file, "pBan");
           PlayerInfo[playerid][pJob] = dini_Int(file, "pJob");
           PlayerInfo[playerid][pCountry] = dini_Int(file, "pCountry");
           IsLogged[playerid] = 1;
           SpawnPlayer(playerid);
           new Welcome[MAX_OUTPUT_MSG];
           format(Welcome, sizeof(Welcome), "Bienvenido %s ! ", PlayerName);
           SendClientMessage(playerid, 0xFFFFFFFFFF, Welcome);
           
	    }
	    else
	   {
		   SendClientMessage(playerid, 0xFFFFFFFFFF, "Lo sentimos, has introducido una clave incorrecta");
		   Kick(playerid);
	   }
   }

	

    return 0;
}

/*#################################################*/
/*        AnswerTest                               */
/*#################################################*/

stock AnswersTest(answerid, playerid)
{
	switch ( answerid )
    {
        case DI_ANSWER0:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER0,DIALOG_STYLE_LIST,"Definirias el metagaming como...","A. Jugar de manera extrema\r\nB. Son los meta-tags de los jugadores\r\nC. Usar informacion OOC en IC\r\nD. Robar a un usuario sin rol","Aceptar", "");
		}
		
		case DI_ANSWER1:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER1,DIALOG_STYLE_LIST,"Definirias el powergaming como...","A. Jugar a los power rangers IC\r\nB. Abusar de que es un juego y realizar acciones que no harias en la vida real\r\nC. Es cuando los administradores abusan de los comandos\r\nD. El powergaming no existe en servidores como este","Aceptar", "");
		}
		
		case DI_ANSWER2:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER2,DIALOG_STYLE_LIST,"Definirias el revenge kill como...","A. Matar a un jugador con Shotgun\r\nB. Matar sin razon en el juego\r\nC. Matar por venganza o volver a la zona donde te han matado anteriormente\r\nD. Matar mas de 4 veces seguidas a un jugador","Aceptar", "");
		}
		
		case DI_ANSWER3:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER3,DIALOG_STYLE_LIST,"Definirias el Deathmatch como...","A. Es cuando disparas o agredes a alguien sin ninguna razon valida\r\nB. El Deathmatch consiste en matar a todo el servidor\r\nC. En servidores como este el Deathmatch nunca ha existido\r\nD. Ordenar la muerte de algun personaje sin razon","Aceptar", "");
		}
		
		case DI_ANSWER4:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER4,DIALOG_STYLE_LIST,"He cometido un delito y un policia me ha capturado roleando...","A. Intento darle un cabezaso para tumbarlo\r\nB. Llamo a un miembro de mi faccion OOC o IC para que venga a salvarme\r\nC. Saldre corriendo cuando el policia menos lo espere\r\nD. Me ha detenido roleando y me tengo que resignar y no hacer powergaming","Aceptar", "");
		}
		
		case DI_ANSWER5:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER5,DIALOG_STYLE_LIST,"La diferencia entre un canal IC y OOC...","A. No hay diferencia, hasta puedo decir fuera del juego que me ayuden\r\nB. Son los canales de television de San Andreas\r\nC. IC es cuando estemos roleando, OOC para el exterior\r\nD. El OOC es para los policias, el IC es solo para mafias","Aceptar", "");
		}
		
		case DI_ANSWER6:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER6,DIALOG_STYLE_LIST,"Me gustaria ser de una faccion...","A. Averiguo OOC quien es el lider y lo busco en el juego\r\nB. Envio un correo o contacto con la administracion\r\nC. Roleo ingame obtener informacion sobre dicha faccion\r\nD. Envio un mensaje privado al lider","Aceptar", "");
		}
		
		case DI_ANSWER7:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER7,DIALOG_STYLE_LIST,"He visto a un jugador usando cheats...","A. Lo ignoro y simplemente lo reporto\r\nB. Empiezo a provocarlo/amenazarlo y reirme de el OOC\r\nC. Activo mis cheats para combatirlo\r\nD. No hago nada","Aceptar", "");
		}
		
		
		case DI_ANSWER8:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER8,DIALOG_STYLE_LIST,"Cuentanos algo acerca del lenguaje utilizado...","A. Pongo lo que me da la gana en el chat IC\r\nB. Escribo usando iconos como estos xD :P :D :)\r\nC. Escribo sin simbolos pero en mayusculas y con faltas de ortografia\r\nD. Intento escribir sin faltas de ortografia y no escribir todo en mayusculas","Aceptar", "");
		}
		
		case DI_ANSWER9:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER9,DIALOG_STYLE_LIST,"Un jugador no ha roleado bien una situacion","A. Arreglamos las cosas viendo quien dice el mejor insulto\r\nB. Empiezo a reportarlo y a llamarlo Anti RP\r\nC. Lo reporto y que se joda, me encanta joder a los novatos\r\nD. Hablo las cosas con el, y le explico lo que hizo mal, si sigue lo reporto","Aceptar", "");
		}
		
		case DI_ANSWER10:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER10,DIALOG_STYLE_LIST,"Me gustaria ser administrador","A. Acoso a los administradores por mensajes\r\nB. Sigo jugando y cumpliendo las normas, y ellos me valoraran\r\nC. Me pongo a reportar personas o a presumir delante de un admin de mi rol\r\nD. Lo pido a gritos que si porfavor me pueden hacer","Aceptar", "");
		}
		
		case DI_ANSWER11:
        {	
			ShowPlayerDialog(playerid,DI_ANSWER11,DIALOG_STYLE_LIST,"Un hombre te asalta y te apunta a la cabeza","A. Roleo la peligrosa situacion, y no me hago el heroe\r\nB. Le digo OOC que si me suelta\r\nC. Yo tambien saco un arma\r\nD. Salgo corriendo usando /intentar","Aceptar", "");
		}
		case DI_ANSWER12:
		{
			ShowPlayerDialog(playerid,DI_ANSWER12,DIALOG_STYLE_LIST,"Estas huyendo de LSPD y sufres un choque","A. Sigo huyendo, soy superman\r\nB. Paro el coche y roleo el fuerte accidente\r\nC. Paro el coche y cuando el policia llegue acelero\r\nD. Me sigo chocando, es divertido","Aceptar", "");
		}
		case DI_ANSWER13:
		{
			ShowPlayerDialog(playerid,DI_ANSWER13,DIALOG_STYLE_LIST,"Eres un miembro de una poderosa mafia o banda...","A. Roleo mi papel pero no abuso del PG\r\nB. Todo el que me desafia saco un arma y le pego un tiro hay mismo\r\nC. Busco problemas con todos, incluso al primer policia que veo\r\nD. Me pongo a disparar en el ayuntamiento","Aceptar", "");
		}
	}
	return 1;
}


/*#################################################*/
/*        OnPlayerText                             */
/*#################################################*/

public OnPlayerText(playerid, text[])
{
	SendTextForPlayers(playerid, text, false);
    return 0;
}

/*#################################################*/
/*        SendTextForPlayers                        */
/*#################################################*/

stock SendTextForPlayers(senderid, text[], bool: me)
{
	new Float: X;
	new Float: Y;
	new Float: Z;
	GetPlayerPos(senderid, X, Y, Z);
	for(new i =0; i<=MAX_PLAYERS; i++)
 	{
  		new Float: Xp;
	    new Float: Yp;
	    new Float: Zp;
	    GetPlayerPos(i, Xp, Yp, Zp);
	    if(IsPlayerConnected(i))
     	{
      		if(IsPlayerInRangeOfPoint(i, 10.0, X, Y, Z))
        	{
		   		new PlayerName[MAX_PLAYER_NAME];
			   	GetPlayerName(senderid, PlayerName, sizeof(PlayerName));
		       	new Message[MAX_OUTPUT_MSG];
   				if(!me)
			   	{
       				format(Message, sizeof(Message), "%s dice: %s", PlayerName, text);
           			SendClientMessage(i, 0xFFFFFFFFF, Message);
			 	}
			 	else
			 	{
				   	format(Message, sizeof(Message), "** %s %s", PlayerName, text);
		           	SendClientMessage(i, 0x81BEF7FF, Message);
		 		}
			}
   		}
  	}
	return 1;
}

/*#################################################*/
/*        SendTextForPlayersGritos                 */
/*#################################################*/

stock SendTextForPlayersGritos(senderid, text[])
{
	new Float: X;
	new Float: Y;
	new Float: Z;
	GetPlayerPos(senderid, X, Y, Z);
	for(new i =0; i<=MAX_PLAYERS; i++)
 	{
  		new Float: Xp;
	    new Float: Yp;
	    new Float: Zp;
	    GetPlayerPos(i, Xp, Yp, Zp);
	    if(IsPlayerConnected(i))
     	{
      		if(IsPlayerInRangeOfPoint(i, 24.0, X, Y, Z))
        	{
		   		new PlayerName[MAX_PLAYER_NAME];
			   	GetPlayerName(senderid, PlayerName, sizeof(PlayerName));
		       	new Message[MAX_OUTPUT_MSG];
       			format(Message, sizeof(Message), "%s grita: %s", PlayerName, text);
           		SendClientMessage(i, 0xFFFFFFFFF, Message);
			 	
			}
   		}
  	}
	return 1;
}

/*#################################################*/
/*        SendTextForPlayersOOC                    */
/*#################################################*/

stock SendTextForPlayersOOC(senderid, text[])
{
	new Float: X;
	new Float: Y;
	new Float: Z;
	GetPlayerPos(senderid, X, Y, Z);
	for(new i =0; i<=MAX_PLAYERS; i++)
 	{
  		new Float: Xp;
	    new Float: Yp;
	    new Float: Zp;
	    GetPlayerPos(i, Xp, Yp, Zp);
	    if(IsPlayerConnected(i))
     	{
      		if(IsPlayerInRangeOfPoint(i, 10.0, X, Y, Z))
        	{
		   		new PlayerName[MAX_PLAYER_NAME];
			   	GetPlayerName(senderid, PlayerName, sizeof(PlayerName));
		       	new Message[MAX_OUTPUT_MSG];
       			format(Message, sizeof(Message), "{B4045F}(OOC) %s dice: {FFFFFF}(( %s ))", PlayerName, text);
           		SendClientMessage(i, 0xFFFFFFFFF, Message);
			 	
			}
   		}
  	}
	return 1;
}
/*#################################################*/
/*        IsValidRolePlayName                      */
/*#################################################*/

stock IsValidRolePlayName(nick[])
{
	new founds = 0;
	for(new i = 0; nick[i] != '\0'; i++)
 	{
  		if(nick[i] == '_') founds++;
  	}
  	if(founds == 1)
  	{
  		return true;
	}
	else
	{
 		return false;
 	}
}

/*#################################################*/
/*       OnPlayerCommandText                       */
/*#################################################*/

public OnPlayerCommandText(playerid, cmdtext[])
{
	
	/* ##################################################################### */
	if( !strcmp ( cmdtext, "/tazer" ) || !strcmp ( cmdtext, "/t" ) )
	{
		if (PlayerInfo[playerid][pFaction] != 1)
		{
			SendClientMessage(playerid, 0xFFFFFFFF, "Usted no es un oficial");
			return 1;
		}
		SendTextForPlayers(playerid, "Lanza una descarga electrica", true);
		new Float: X, Float:Y, Float: Z;
		GetPlayerPos(playerid, X, Y , Z);
		for(new i = 0; i< MAX_PLAYERS; i++)
		{
			if(IsPlayerInRangeOfPoint(i, 4.0, X, Y,Z) && i != playerid)
			{
				SendTextForPlayers(i, "ha sufrido una descarga electrica a causa del tazer", true);
				SendTextForPlayers(i, "se encuentra aturdido por la gran descarga electrica", true);
				TogglePlayerControllable(i, 0);
				return 1;
			}
		}
		SendClientMessage(playerid, 0xFFFFFFFF, "No hay nadie que este a tu alcanze!");
		return 1;
	}
	
	/* ##################################################################### */
	if( !strcmp ( cmdtext, "/abrircarcel" ) )
	{
		if ( PlayerInfo[playerid][pFaction] == 1)
		{
			if(IsPlayerInRangeOfPoint(playerid, 8.0, 200.12127685547, 159.59106445313, 1004.5933837891))
			{
				MoveObject(LVPD_GATE, 200.12127685547, 164.59106445313, 1004.5933837891, 2.00);
				SendTextForPlayers(playerid, "saca una llave electronica de su bolsillo y acciona la puerta", true);
			}
			else
			{
				SendClientMessage(playerid, 0xFFFFFFFFFF, "No estas demasiado cerca para usar la llave magnetica");
			}
		}
		return 1;
	}
	
	/* ##################################################################### */
	if( !strcmp ( cmdtext, "/cerrarcarcel" ) )
	{
		if ( PlayerInfo[playerid][pFaction] == 1 )
		{
			if(IsPlayerInRangeOfPoint(playerid, 8.0, 200.12127685547, 159.59106445313, 1004.5933837891))
			{
				MoveObject(LVPD_GATE, 200.12127685547, 159.59106445313, 1004.5933837891, 2.00);
				SendTextForPlayers(playerid, "saca una llave electronica de su bolsillo y cierra la puerta", true);
			}
			else
			{
				SendClientMessage(playerid, 0xFFFFFFFFFF, "No estas demasiado cerca para usar la llave magnetica");
			}
				
		}
		return 1;
	}

	/* ##################################################################### */			
	
	ProccessCmd(playerid, cmdtext);
	return 1;
}

/*#################################################*/
/*       ProcessCmd                                */
/*#################################################*/


stock ProccessCmd(playerid, cmdtext[]) 
{
	new       cmd[MAX_CMD_LEN];
	new params[MAX_OUTPUT_MSG];
	new i;
	for (i =0; cmdtext[i] != ' '; i++ )
	{
		cmd[i] = cmdtext[i];
  	}
  	cmd[i+1] = '\0';
  	new p = 0;
	for(i = i + 1; cmdtext[i] != '\0'; i++)
	{
		params[p] = cmdtext[i];
		p++;
	}
	params[p] = '\0';
	OnUserCMD(playerid, cmd, params);
}

/*#################################################*/
/*             OnUserCMD                           */
/*#################################################*/


stock OnUserCMD(playerid, cmd[], params[])
{
	if ( ! strcmp ( cmd, "/me") )
	{
		SendTextForPlayers(playerid, params, true);		
	}
	
	if ( ! strcmp ( cmd, "/g")  || !strcmp ( cmd, "/gritar"))
	{
		new Float: X;
		new Float: Y;
		new Float: Z;
		new Float: Aux;
		GetPlayerPos(playerid, X, Y , Z);
		Aux = X;
		for(new i =18632; i<19307; i++)
		{
			Aux = Aux + 5.0;
			CreateObject(i, Aux, Y, Z, 0, 0, 0);
			new m[400];
			format(m, sizeof(m), "ID del objeto: %d", i);
			
			Create3DTextLabel(m,0x008080FF,Aux, Y, Z,40.0,0);
		}
			
		SendTextForPlayersGritos(playerid, params);		
	}
	if ( ! strcmp ( cmd, "/b") )
	{
		SendTextForPlayersOOC(playerid, params);		
	}
	if ( ! strcmp ( cmd, "/dni") )
	{
		new pWantSeeDNI[MAX_PLAYER_NAME];
	    GetPlayerName(strval(params), pWantSeeDNI, sizeof(pWantSeeDNI) );
	    new DNImsg[MAX_OUTPUT_MSG];
	    format(DNImsg, sizeof(DNImsg), "Entrega su D.N.I a %s", pWantSeeDNI);
	    SendTextForPlayers(playerid, DNImsg, true);	
	    ShowDNI(playerid, strval(params));
	}
	if ( ! strcmp ( cmd, "/r"))
	{
		RadioTalk(playerid, params);
	}
				

}

/*#################################################*/
/*             RadioTalk                           */
/*#################################################*/

stock RadioTalk(playerid, voice[])

{
	
    if(PlayerInfo[playerid][pFaction] == FA_POLICE)
    {
		new RadioOutput[MAX_OUTPUT_MSG];
		format(RadioOutput, sizeof(RadioOutput), "**[LV-PD]Radio - %s - Cambio y corto ** Transmision finalizada", voice);
		for(new i =0; i <= MAX_PLAYERS; i++)
		{
			if(PlayerInfo[i][pFaction] == FA_POLICE)
			{
				SendClientMessage(i, 0x8181F7FF, RadioOutput);
			}
		}
	}
	return 1;	
}

/*#################################################*/
/*             ShowDNI                             */
/*#################################################*/

stock ShowDNI(playerid, toid)
{
	new Float:X, Float:Y, Float:Z;
	GetPlayerPos(playerid, X, Y, Z);
	if( ! IsPlayerInRangeOfPoint(toid, 4.0, X,Y,Z) )
	{
		SendClientMessage(playerid, 0xFFFFFFFFF, "No estas demasiado cerca como para mostrarle tu D.N.I!!");
	}
	else
	{
		new PlayerName[MAX_PLAYER_NAME];
		new Name[40];
		GetPlayerName(playerid, PlayerName, sizeof(PlayerName) );
		format(Name, sizeof(Name), "Nombre y apellidos: %s", PlayerName);
		new ID[30];
        format(ID, sizeof(ID), "NIF: %d", PlayerInfo[playerid][pId]);
        new AgeM[50];
        if(PlayerInfo[playerid][pAge] >= 18)
        {
			format(AgeM, sizeof(AgeM), "Edad: %d (Mayor de edad)", PlayerInfo[playerid][pAge]);
		}
		else
		{
			format(AgeM, sizeof(AgeM), "Edad: %d (Menor de edad)", PlayerInfo[playerid][pAge]);
		}
		
        new Married[100];
        if(PlayerInfo[playerid][pMarried] == 0)
        {
			format(Married, sizeof(Married), "Estado civil: Soltero");
		}
		if(PlayerInfo[playerid][pMarried] == 1)
		{
			format(Married, sizeof(Married), "Estado civil: Casado");
		}
		
		new mCountry[50];
		
		switch(PlayerInfo[playerid][pCountry])
		{
			case C_SPAIN:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Espana");
			}
			case C_ECUADOR:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Ecuador");
			}
			case C_VENEZUELA:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Venezuela");
			}
			case C_ARGENTINA:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Argentina");
			}
			case C_MEXICO:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Mexico");
			}
			case C_OTHER:
			{
				format(mCountry, sizeof(mCountry), "Pais de procedencia: Desconocido");
			}
		}

	    SendClientMessage(toid,0xFF8000FF, "----- ## Documento nacional de identidad ## ------");
	    SendClientMessage(toid,0xBDBDBDFF, Name);
        SendClientMessage(toid,0xBDBDBDFF, ID);
        SendClientMessage(toid,0xBDBDBDFF, AgeM);
        SendClientMessage(toid,0xBDBDBDFF, Married);
        SendClientMessage(toid,0xBDBDBDFF, Country);
	}

}

/*#################################################*/
/*             IsPoliceCar                         */
/*#################################################*/

stock IsPoliceCar(car)

{

new PD_CARS[] =
{
	427, 523, 427, 490,
    528, 598, 599,  501	
};

new model = GetVehicleModel(car);

for (new i = 0; i< sizeof(PD_CARS); i++)
{
	if(model == PD_CARS[i]) return 1;	  
} 

return 0;
	
}

/*#################################################*/
/*             OnPlayerEnterVehicle                */
/*#################################################*/

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(IsPoliceCar(vehicleid) && ispassenger == 0)
	{
		if(PlayerInfo[playerid][pFaction] != FA_POLICE)
		{
			CallAlarm(playerid, vehicleid);
		}
	}
	

    return 1;	
}

/*#################################################*/
/*             CallAlarm                           */
/*#################################################*/

stock CallAlarm(playerid, vehicleid)
{
            new Float: X;
			new Float: Y
			new Float: Z;
			GetVehiclePos(vehicleid, X, Y, Z);
			RemovePlayerFromVehicle(vehicleid);
			SendClientMessage(playerid, 0xFE2E2EFF, "Haz forzado la entrada a un vehiculo del gobierno - la alarma ha saltado");
			new id;
			if(AlarmNow > MAX_ALARMS)
			{
				AlarmNow = 0;
				id = AlarmNow;
			}
			else
			{
				id = AlarmNow + 1;
			}
			KillTimer(AlarmHandler[playerid]);
			GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	        SetVehicleParamsEx(vehicleid, engine, lights, 1, doors, bonnet, boot, objective);
			AlarmHandler[playerid] = SetTimerEx("AlarmSound",1000,true,"iii", vehicleid, id, playerid);	
	
}

/*#################################################*/
/*             AlarmSound                          */
/*#################################################*/

public AlarmSound(vehicleid, id, playerid)
{
	AlarmCount[id]++;
	if(AlarmCount[id] > 35)
	{
		AlarmCount[id] = 0;
		//Aqui apagamos la alarma
		GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
		SetVehicleParamsEx(vehicleid, engine, lights, 0, doors, bonnet, boot, objective)
	}
	
	
}

/*#################################################*/
/*             CallAnswers                         */
/*#################################################*/

stock CallAnswers(playerid)
{
	
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    if(!IsValidRolePlayName(PlayerName))
	{
		SendClientMessage(playerid, 0xFFFFFFFFF, "Para poder jugar en este servidor necesitas un nombre con este formato: Nombre_Apellido");
		Kick(playerid);
	}
	new tmpMsg[MAX_OUTPUT_MSG];
    format(tmpMsg, sizeof(tmpMsg), "Bienvenido %s, su cuenta no esta registrada.\nLe diremos lo que usted puede hacer.", PlayerName);
    ShowPlayerDialog(playerid, INIT_STEP1, DIALOG_STYLE_MSGBOX, "Atencion", tmpMsg, "Acepto", "");	
    	
}



/*#################################################*/
/*             CallLogin                           */
/*#################################################*/

stock CallLogin(playerid)
{
	new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    TextDrawSetString(DrawName[playerid], PlayerName);	
    TextDrawShowForPlayer(playerid,DrawName[playerid]);	
    new tmpMsg[MAX_OUTPUT_MSG];
    format(tmpMsg, sizeof(tmpMsg), "Bienvenido a Stella RolePlay %s.\nEscriba su clave en la caja de texto inferior", PlayerName);
    ShowPlayerDialog(playerid, DI_LOGIN, DIALOG_STYLE_INPUT, "Login", tmpMsg, "Login", "Cancelar");
}

/*#################################################*/
/*             CalllRegister                       */
/*#################################################*/

stock CallRegister(playerid, age, country, password[])
{

        new PlayerName[MAX_PLAYER_NAME];
        new file[MAX_PLAYER_NAME + 15];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        format(file, sizeof(file), "usuarios/%s.ini", PlayerName);	
        dini_Create(file);
        
        
        new n1, n2, n3, n4;
        n1 = random(500);
        n2 = random(500);
        n3 = random(500);
        n4 = random(500);
        new id[MAX_OUTPUT_MSG];
        format(id, sizeof(id), "%d%d%d%d", n1, n2, n3, n4);
        
        dini_IntSet(file, "pId", strval(id));
        dini_IntSet(file, "pPassword", udb_hash(password));
        dini_IntSet(file, "pMoney", 300);
        dini_IntSet(file, "pAge", age);
        dini_IntSet(file, "pDriveLicense", 0);
        dini_IntSet(file, "pWeaponLicense", 0);
        dini_IntSet(file, "pBankMoney", 0);
        dini_IntSet(file, "pMarried", 0);
        dini_IntSet(file, "pAdminLevel", 0);
        dini_IntSet(file, "pFaction", 0);
        dini_IntSet(file, "pFactionLevel", 0);
        dini_IntSet(file, "pJailed", 0);
        dini_IntSet(file, "pJailedTime", 0);
        dini_IntSet(file, "pBan", 0);
        dini_IntSet(file, "pJob", 0);
        dini_IntSet(file, "pCountry", country);
        dini_IntSet(file, "pHavePhone", 0);
        dini_IntSet(file, "pPhoneNumber", 0);
        dini_IntSet(file, "pHaveBankAccount", 0);
        dini_IntSet(file, "pBankAccount", 0);
        dini_IntSet(file, "pSkin", 26);
        dini_IntSet(file, "pDriveTeoric", 0);
        
    

        PlayerInfo[playerid][pId] = dini_Int(file, "pId");
        PlayerInfo[playerid][pPassword] = dini_Int(file, "pPassword");
        PlayerInfo[playerid][pMoney] = dini_Int(file, "pMoney");
        PlayerInfo[playerid][pAge] = dini_Int(file, "pAge");
        PlayerInfo[playerid][pDriveLicense] = dini_Int(file, "pDriveLicense");
        PlayerInfo[playerid][pWeaponLicense] = dini_Int(file, "pWeaponLicense");
        PlayerInfo[playerid][pBankMoney] = dini_Int(file, "pBankMoney");
        PlayerInfo[playerid][pMarried] = dini_Int(file, "pMarried");
        PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "pAdminLevel");
        PlayerInfo[playerid][pFaction] = dini_Int(file, "pFaction");
        PlayerInfo[playerid][pFactionLevel] = dini_Int(file, "pFactionLevel");
        PlayerInfo[playerid][pJailed] = dini_Int(file, "pJailed");
        PlayerInfo[playerid][pJailedTime] = dini_Int(file, "pJailedTime");
        PlayerInfo[playerid][pBan] = dini_Int(file, "pBan");
        PlayerInfo[playerid][pJob] = dini_Int(file, "pJob");
        PlayerInfo[playerid][pCountry] = dini_Int(file, "pCountry");
        PlayerInfo[playerid][pHavePhone] = dini_Int(file, "pHavePhone");
        PlayerInfo[playerid][pPhoneNumber] = dini_Int(file, "pPhoneNumber");
        PlayerInfo[playerid][pHaveBankAccount] = dini_Int(file, "pHaveBankAccount");
        PlayerInfo[playerid][pBankAccount] = dini_Int(file, "pBankAccount");
        PlayerInfo[playerid][pSkin] = dini_Int(file, "pSkin");
        PlayerInfo[playerid][pDriveTeoric] = dini_Int(file, "pDriveTeoric");
    
    	
}

/*#################################################*/
/*             OnPlayerDisconnect                  */
/*#################################################*/

public OnPlayerDisconnect(playerid)
{
        new PlayerName[MAX_PLAYER_NAME];
        new file[MAX_PLAYER_NAME + 15];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        format(file, sizeof(file), "usuarios/%s.ini", PlayerName);
        if(IsLogged[playerid] == 1)
        {
			dini_IntSet(file, "pMoney", PlayerInfo[playerid][pMoney]);
			dini_IntSet(file, "pDriveLicense", PlayerInfo[playerid][pDriveLicense]);
			dini_IntSet(file, "pWeaponLicense", PlayerInfo[playerid][pWeaponLicense]);
			dini_IntSet(file, "pBankMoney", PlayerInfo[playerid][pBankMoney]);
			dini_IntSet(file, "pMarried", PlayerInfo[playerid][pMarried]);
			dini_IntSet(file, "pMoney", PlayerInfo[playerid][pMoney]);
			dini_IntSet(file, "pAdminLevel", PlayerInfo[playerid][pAdminLevel]);
			dini_IntSet(file, "pFaction", PlayerInfo[playerid][pFaction]);
			dini_IntSet(file, "pFactionLevel", PlayerInfo[playerid][pFactionLevel]);
			dini_IntSet(file, "pJailed", PlayerInfo[playerid][pJailed]);
			dini_IntSet(file, "pJailedTime", PlayerInfo[playerid][pJailedTime]);
			dini_IntSet(file, "pBan", PlayerInfo[playerid][pBan]);
			dini_IntSet(file, "pJob", PlayerInfo[playerid][pJob]);
			dini_IntSet(file, "pHavePhone", PlayerInfo[playerid][pHavePhone]);
			dini_IntSet(file, "pPhoneNumber", PlayerInfo[playerid][pPhoneNumber]);
			dini_IntSet(file, "pHaveBankAccount", PlayerInfo[playerid][pHaveBankAccount]);
			dini_IntSet(file, "pBankAccount", PlayerInfo[playerid][pBankAccount]);
			dini_IntSet(file, "pSkin", PlayerInfo[playerid][pSkin]);
			dini_IntSet(file, "pDriveTeoric", PlayerInfo[playerid][pDriveTeoric]);
		}		
	
	
}
/*#################################################*/
/*             CalllRegisterFinally                */
/*#################################################*/

stock CallRegisterFinally(playerid)
{
	
	SetPlayerInterior(playerid, 14);
	SetPlayerPos(playerid, -1831.6558,18.1555,1061.1436);
	SetPlayerHoldingObject(playerid, 1210, 6, 0.289999, 0.079999, -0.000000, 0.000000, -100.000000, 1.000000);
	SetPlayerCameraPos(playerid, -1832.2156,6.8017,1061.1436);
	SetPlayerCameraLookAt(playerid, -1825.2156,45.8017,1061.1436);
	SendTextForPlayers(playerid, "Recoje su maletin de la cinta transportadora", true);
    SetPlayerFacingAngle( playerid, 180 );
    SendTextForPlayers(playerid, "Se dirije a la salida", true);
    ApplyAnimation(playerid,"PED","WALK_player",4.1,1,1,1,1,1);	
    SetTimerEx("SpawnRegisteringPlayer",8000,false,"i",playerid);

}

/*#################################################*/
/*          OnPlayerKeyStateChange                 */
/*#################################################*/

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if (PRESSED(KEY_FIRE))
	{
		if(IsPlayerOnShop[playerid] == 1)
		if(IsPlayerInRangeOfPoint(playerid, 4.0, 181.4218,-91.5893,1002.0234))
		{
			if(IsPlayerInRangeOfPoint(playerid, 4.0, 181.4218,-91.5893,1002.0234))
			{
			switch(Sex_clothe[playerid])
			{
				case MEN:
				{
					SetPlayerSkin(playerid, Boy_Skins[pos_Boy[playerid]]);
					//TogglePlayerControllable(playerid, 1);
					pos_Boy[playerid]++;
					if(pos_Boy[playerid] == sizeof(Boy_Skins) )
					{
						pos_Boy[playerid] = 0;
					}
				}
				case GIRL:
				{
					SetPlayerSkin(playerid, Girl_Skins[pos_Girl[playerid]]);
					//TogglePlayerControllable(playerid, 1);
					pos_Girl[playerid]++;
					if(pos_Girl[playerid] == sizeof(Girl_Skins))
					{
						pos_Girl[playerid] = 0;
					}
				}
			}
		}
	}
	    else
	{
		ShowPlayerDialog(playerid, D_SHOPCLOTHES_BUY_ERROR2, DIALOG_STYLE_MSGBOX, "Mmm", "Acercate al probador, no te desnudes en publico", "Aceptar", "");
	}


	}
	
	if(PRESSED(KEY_SPRINT))
	{
		if(IsPlayerOnShop[playerid] == 1)
		{
			if(GetPlayerMoney(playerid) >= 50)
			{
				if(Sex_clothe[playerid] == MEN)
				{
					if(Boy_Skins[pos_Boy[playerid]] > 0)
					PlayerInfo[playerid][pSkin] = Boy_Skins[pos_Boy[playerid] - 1];
					else
					PlayerInfo[playerid][pSkin] = Boy_Skins[pos_Boy[playerid]];
					
				}
				if(Sex_clothe[playerid] == GIRL)
				{
					if(Girl_Skins[pos_Girl[playerid]] > 0)
					PlayerInfo[playerid][pSkin] = Girl_Skins[pos_Girl[playerid] - 1];
					else
					PlayerInfo[playerid][pSkin] = Girl_Skins[pos_Girl[playerid]];
				}
					
				SetPlayerMoney(playerid, GetPlayerMoney(playerid) - 50 );
				ShowPlayerDialog(playerid, D_SHOPCLOTHES_BUY_OK, DIALOG_STYLE_MSGBOX, "Ropa cambiada", "Haz cambiado tu ropa con exito - te ha costado 50$", "Aceptar", "");
				pos_Girl[playerid] = 0;
				pos_Boy[playerid] = 0;
				IsPlayerOnShop[playerid] = 0;
				TogglePlayerControllable(playerid, 1);
			}
			else
			{
				PlayerInfo[playerid][pSkin] = FirstSkin[playerid];
				SetPlayerSkin(playerid, FirstSkin[playerid]);
				ShowPlayerDialog(playerid, D_SHOPCLOTHES_BUY_ERROR, DIALOG_STYLE_MSGBOX, "Error", "{AA3333}No dispones de dinero suficiente para adquirir esta prenda", "Aceptar", "");
				pos_Girl[playerid] = 0;
				pos_Boy[playerid] = 0;
				IsPlayerOnShop[playerid] = 0;
				TogglePlayerControllable(playerid, 1);
			}
		}
			

				
	}
	
	return 1;
}


/*#################################################*/
/*            SpawnRegisteringPlayer               */
/*#################################################*/

public SpawnRegisteringPlayer(playerid)
{
ClearAnimations(playerid);
StopPlayerHoldingObject(playerid);
SetCameraBehindPlayer(playerid);
SetPlayerInterior(playerid, 0);	
SetPlayerPos(playerid, 2127.4985,2374.9167,10.8203);
SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
IsLogged[playerid] = 1;
}

stock SelectSpawn(playerid)
{
	
switch(PlayerInfo[playerid][pFaction])
{
	case FA_POLICE:
	{
		if(PlayerInfo[playerid][pFactionLevel] == 1)
		{
			SetPlayerSkin(playerid, 282);
		}
		if(PlayerInfo[playerid][pFactionLevel] == 2)
		{
			SetPlayerSkin(playerid, 283);
		}
		if(PlayerInfo[playerid][pFactionLevel] == 3)
		{
			SetPlayerSkin(playerid, 288);
		}
		SetPlayerPos(playerid, 289.4879, 174.1790, 1007.1794);
		SetPlayerInterior(playerid, 3);
		
	}
	case FA_RUSSIAN_MAFIA:
	{
    if(lol == 1)
    {
		SetPlayerInterior(playerid, 0);
		SetPlayerPos(playerid, 1458.7157,2758.7258,10.5528);
	}
	
}

	
	

	
	
	
}
